﻿package MyUI{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	import flash.utils.*;
	public class MyMenu extends MyFrame{
		var index:Dictionary;
		var selectBar:Shape;
		public var callback:Function;
		public function MyMenu(parent){
			super(parent);
			index = new Dictionary();
			selectBar = new Shape();
			addChild(selectBar);
		}
		public function addItem(label:String,value = null){
			var item:TextField = new TextField();
			item.width = contentWidth;
			item.height = 20;
			item.text = label;
			item.selectable = false;
			index[item] = value === null ? label : value;
			item.addEventListener(MouseEvent.CLICK,onClick);
			item.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			content.append(item);
		}
		private function onOver(e:MouseEvent){
			selectBar.y = e.target.y+content.y;
		}
		private function onClick(e:MouseEvent){
			callback(index[e.target]);
		}
		override public function setSize(w:Number,h:Number):void{
			super.setSize(w,h);
			selectBar.graphics.beginFill(0x02CA8D,0.7);
			selectBar.graphics.drawRect(0,0,w,20);
			selectBar.graphics.endFill();
			selectBar.y = content.y;
		}
		public function clear(){
			content.clear();
		}
	}
}